package demo3;

import java.util.Stack;

public class Test1 {
    public static void main(String[] args) {
        String s = "({})";
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (isleft(s.charAt(i))) {
                stack.push(s.charAt(i));
            } else {
                if (!stack.isEmpty()) {
                    char left = stack.pop();
                    if (!isMatching(left,s.charAt(i))) {
                        //return false;
                    }
                } else {
                    //return false;
                }
            }
        }
        //return stack.isEmpty();

    }
    //判断是不是左括号
    public static boolean isleft (char ch) {
        if (ch == '(' || ch == '[' || ch == '{') {
            return true;
        }
        return false;
    }
    //比较是否匹配
    public static boolean isMatching (char ch1, char ch2) {
        if ((ch1 == '(' && ch2 == ')') || (ch1 == '[' && ch2 == ']')
                || (ch1 == '{' && ch2 == '}')) {
            return true;
        }
        return false;
    }
}
